import * as types from "./mutation-types";
import Api from "api/api";

const state = {
  columnTree: {},
  columnMenu: {},
  columnSave: "",
  columnEdit: "",
  columnRoleList: "",
  columnRoleSave: "",
  columnFormList: "",
  templateList: "",
  myColumnList: [],
  modelList: "",
  clearInfo: ""
};

const getters = {
  clearInfo: state => state.clearInfo,
  myColumnList: state => state.myColumnList,
  columnTree: state => state.columnTree,
  columnMenu: state => state.columnMenu,
  columnSave: state => state.columnSave,
  columnEdit: state => state.columnEdit,
  columnRoleList: state => state.columnRoleList,
  columnRoleSave: state => state.columnRoleSave,
  columnFormList: state => state.columnFormList,
  templateList: state => state.templateList,
  modelList: state => state.modelList
};

const actions = {
  columnListUsingGETS({ commit }, param) {
    return Api.columnListUsingGET(param).then(ret => {
      commit(types.UPDATE_LISTU_LIST, ret.data);
      return ret;
    });
  },
  columnTreeUsingGETS({ commit }, param) {
    return Api.getNewsItemPageList(param).then(ret => {
      commit(types.UPDATE_COLUMN_LIST, ret.data);
      return ret;
    });
  },
  //我的栏目
  getMyColumnList({ commit }, param) {
    return Api.getArticleList(param).then(ret => {
      commit(types.UPDATE_MY_COLUMN_LIST, ret.data);
      return ret;
    });
  },

  // 资讯栏目

  getInformationList({ commit }, param) {
    return Api.getAllRecoveryItem(param).then(ret => {
      commit(types.UPDATE_MY_COLUMN_LIST, ret.data);
      return ret;
    });
  },
  //栏目保存
  columnSaveUsingPOSTS({ commit }, param) {
    return Api.addOrUpdateNewsItem(param).then(ret => {
      commit(types.UPDATE_COLUMN_SAVE_LIST, ret.data);
      return ret;
    });
  },
  //栏目修改
  columnEditUsingPOSTS({ commit }, param) {
    return Api.addOrUpdateNewsItem(param).then(ret => {
      commit(types.UPDATE_COLUMN_EDIT_LIST, ret.data);
      return ret;
    });
  },
  //栏目删除
  columnDelUsingPOSTS({ commit }, param) {
    return Api.deleteNewsItemById(param).then(ret => {
      return ret;
    });
  },
  // 栏目-角色关系列表
  getColumnRoleUsingGETS({ commit }, param) {
    return Api.getRoleList(param).then(ret => {
      commit(types.UPDATE_COLUMN_ROLE_LIST, ret.data);
      return ret;
    });
  },
  //栏目-角色关系保存
  saveColumnRoleUsingPOSTS({ commit }, param) {
    return Api.saveNewsItemRole(param).then(ret => {
      commit(types.UPDATE_COLUMN_ROLE_SAVE_LIST, ret.data);
      return ret;
    });
  },

  //栏目详情
  columnEditUsingPOST_1S({ commit }, param) {
    return Api.getNewsItemById(param).then(ret => {
      commit(types.UPDATE_COLUMN_FORM_LIST, ret.data);
      return ret;
    });
  },
  //模板列表
  templateListUsingGETS({ commit }, param) {
    return Api.templateListUsingGET(param).then(ret => {
      commit(types.UPDATE_TEMPLATE_LIST, ret.data);
      return ret;
    });
  },
  //模型列表
  contentModelListUsingGETS({ commit }, param) {
    return Api.contentModelListUsingGET(param).then(ret => {
      commit(types.UPDATE_MODEL_LIST, ret.data);
      return ret;
    });
  },
  // 清空session标记
  updateClearInfo({ commit }, param) {
    commit(types.CLEAR_INFO, param);
  }
};
const mutations = {
  [types.CLEAR_INFO](state, payload) {
    state.clearInfo = payload;
  },
  [types.UPDATE_MY_COLUMN_LIST](state, payload) {
    state.myColumnList = payload;
  },
  [types.UPDATE_LISTU_LIST](state, payload) {
    state.columnMenu = payload;
  },
  [types.UPDATE_COLUMN_LIST](state, payload) {
    state.columnTree = payload;
  },
  [types.UPDATE_COLUMN_SAVE_LIST](state, payload) {
    state.columnSave = payload;
  },
  [types.UPDATE_COLUMN_EDIT_LIST](state, payload) {
    state.columnEdit = payload;
  },
  [types.UPDATE_COLUMN_ROLE_LIST](state, payload) {
    state.columnRoleList = payload;
  },
  [types.UPDATE_COLUMN_ROLE_SAVE_LIST](state, payload) {
    state.columnRoleSave = payload;
  },
  [types.UPDATE_COLUMN_FORM_LIST](state, payload) {
    state.columnFormList = payload;
  },
  [types.UPDATE_TEMPLATE_LIST](state, payload) {
    state.templateList = payload;
  },
  [types.UPDATE_MODEL_LIST](state, payload) {
    state.modelList = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
